package com.surfilter.phantomjs.app;

import com.surfilter.exception.OprateException;
import com.surfilter.phantomjs.manage.PhantomJSDriverPools;
import com.surfilter.phantomjs.util.WebCrawlUtils;
import org.openqa.selenium.WebElement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Application {
    private static Logger logger = LoggerFactory.getLogger(Application.class);

    public static void main(String[] args) throws OprateException, InterruptedException {
//        ApplicationContext context = new ClassPathXmlApplicationContext("spring-main.xml");
//        logger.info("程序启动完成");
        PhantomJSDriverPools.initDriverPoolsByPort(3);
        for(int i=0;i<1000;i++){
            new Thread(new Runnable() {
                public void run() {
                    try {
                        WebCrawlUtils webCrawlUtils = new WebCrawlUtils();
                        boolean initDriverByPools = webCrawlUtils.initDriverByPools();
                        boolean flag = webCrawlUtils.openWebPage("https://www.baidu.com");
                        WebElement element = webCrawlUtils.findElementByCssSelector("html > head > title");
                        logger.info("title ： {}",element.toString());
                        webCrawlUtils.close();
                        logger.info("...end");
                    } catch (OprateException | InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }).start();
            Thread.sleep(10000);
        }
    }
}
